<?php
	class Admincp_Model_Fashioncategory extends Zendvn_Model_Nested
	{
		protected $_name = 'fashion_category';
		protected $_primary = 'id';
		protected $_db;
		
		public function __construct()
		{
			$this->_db = Zend_Registry::get('db');
		}
        
        public function listCategory()
		{
			$sql = $this->_db->select()
							 ->from($this->_name)
							 ->order('lft ASC');
			$result = $this->_db->fetchAll($sql);
			return $result;
		}
        
        public function listItemForProduct()
        {
            $sql = $this->_db->select()
							 ->from($this->_name)
                             ->where('status = 1')
							 ->order('lft ASC');
			$result = $this->_db->fetchAll($sql);
			return $result;
        }
        
        public function checkHasChild($id)
        {
            $sql = $this->_db->select()
                            ->from($this->_name, array('id'))
                            ->where('parents = ?', $id);
            $result = $this->_db->fetchAll($sql);
            return count($result);
        }
        
        public function saveItem($data, $option = null)
        {
            if($option == 'create') {
                $this->_db->insert($this->_name, $data);
            }
            else if($option == 'update') {
                $where = $this->getAdapter()->quoteInto('id = ?', $data['id']);
                $this->_db->update($this->_name, $data, $where);
            }
        }
    }
